package com.leyou.user.controller;

import com.leyou.user.entity.User;
import com.leyou.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 校验用户名和手机号唯一性
     */
    @GetMapping("/check/{data}/{type}")
    public ResponseEntity<Boolean> checkData(
            @PathVariable("data") String data,
            @PathVariable("type") Integer type
    ) {
        Boolean isCanUser = userService.checkData(data, type);
        return ResponseEntity.ok(isCanUser);
    }
    /**
     * 用户注册
     */
    @PostMapping("/register")
    public ResponseEntity<Void> register(
            User user,
            @RequestParam("code")String code
    ){
        userService.register(user,code);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

}
